define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jy/design/index' + location.search,
                    add_url: 'jy/design/add',
                    edit_url: 'jy/design/edit',
                    del_url: 'jy/design/del',
                    multi_url: 'jy/design/multi',
                    import_url: 'jy/design/import',
                    table: 'design',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'update_time',
                search: false,
                undefinedText: '',
                exportOptions: {
                    fileName: 'export_' + Moment().format("YYYY-MM-DD"),
                    ignoreColumn: ['operate'] //默认不导出第一列(checkbox)与操作(operate)列
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'design_name', title: __('Design_name'), operate: 'LIKE'},
                        {
                            field: 'cover_images',
                            title: __('Cover_images'),
                            operate: false,
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.images
                        },
                        {field: 'layout_text', title: __('Layout_ids'), operate: false, visible: false},
                        {field: 'style_text', title: __('Style_ids'), operate: false, visible: false},
                        {field: 'space_text', title: __('Space_ids'), operate: false, visible: false},
                        {field: 'scan_count', title: __('Scan_count'), operate: false},
                        {field: 'scan_user_count', title: __('Scan_user_count'), operate: false},
                        {field: 'share_count', title: __('Share_count'), operate: false},
                        {field: 'share_user_count', title: __('Share_user_count'), operate: false},
                        {field: 'praise_count', title: __('Praise_count'), operate: false,},
                        {field: 'praise_user_count', title: __('Praise_user_count'), operate: false},
                        {
                            field: 'cover_to_url',
                            title: __('Cover_to_url'),
                            formatter: Table.api.formatter.url,
                            operate: false,
                            visible: false
                        },
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"1": __('Status 1'), "2": __('Status 2'), "0": __('Status 0')},
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'create_time',
                            title: __('Create_time'),
                            addclass: 'datetimerange',
                            operate: false
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $(document).on("fa.event.appendfieldlist", ".btn-append", function (e, obj) {
                Form.events.plupload(obj);
                Form.events.faselect(obj);
                Form.events.selectpicker(obj);
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on("fa.event.appendfieldlist", ".btn-append", function (e, obj) {
                Form.events.plupload(obj);
                Form.events.faselect(obj);
                Form.events.selectpicker(obj);
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});